package com.icim.csot.exporter.job;

import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.icim.core.pojo.FtpConfigure;
import com.icim.core.service.IAlarmSenderService;
import com.icim.core.service.IFtpService;
import com.icim.csot.exporter.csventity.CsotDefectDataCsvEntity;
import com.icim.csot.exporter.mapkey.OpeKey;
import com.icim.dao.BisOpeDao;
import com.icim.dao.HisRetPrdInfoDao;
import com.icim.dao.RetPrdGrdInfoDao;
import com.icim.dao.RetPrdInfoDao;
import com.icim.dao.RetPrdJgeDao;
import com.icim.dao.RetWoDao;
import com.icim.def.ComDef;
import com.icim.entity.Bis_ope;
import com.icim.entity.His_ret_prd_info;
import com.icim.entity.Ret_prd_info;
import com.icim.entity.Ret_prd_jge;
import com.icim.entity.Ret_wo;
import com.icim.util.CsvFileWriterUtil;
import com.icim.util.GzCompressUtil;
import com.icim.util.TimeUtil;

/**
 * export SPC data with parameter name CDPC && CZPC send to CSOT FTP Service
 * 
 * @author XINLIN
 *
 */
public class CsotExportDefectInfoJob {

    private final static Logger logger = LoggerFactory.getLogger(CsotExportDefectInfoJob.class);
    private final static int STAGE_IQC = 1;
    private final static int STAGE_JB_QA = 2;
    private final static int STAGE_DM_QA = 3;
    private final static String IQC_OPE_ID = "JB-01";
    private final static String JB_QA_OPE_ID = "JB-10";
    private final static String DM_QA_OPE_ID = "DM-05";
    private final static String DM_HXQC_OPE_ID = "DM-07";
    private final static String COMMON_OPE_VER = "00000";
    private int global_IqcPelLvl;
    private int global_jbQaPelLvl;
    private int global_dmQaPelLvl;

    private Timestamp beginTimestamp;
    private Timestamp endTimestamp;
    private Timestamp indexTimestamp;
    private FtpConfigure ftpConfigure;
    private int endTimeMak;
    private String strEndTime;

    @Resource
    private RetWoDao retWoDao;
    @Resource
    private RetPrdInfoDao retPrdInfoDao;
    @Resource
    private HisRetPrdInfoDao hisRetPrdInfoDao;
    @Resource
    private RetPrdJgeDao retPrdJgeDao;
    @Resource
    private BisOpeDao bisOpeDao;

    private IFtpService ftpService;
    
    @Resource
    private IAlarmSenderService alarmSenderService;


    public void subMainProc() {
        logger.info("export defect system running .....");

        /**
         * get time period : begin time & end time
         */
        

        try {
        	getTimePeriod();
			subMainProc2();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			String errorMsg="defect数据回传失败，开始时间："+beginTimestamp+"  结束时间："+endTimestamp+"\n"+"失败原因："+e.getMessage();
        	alarmSenderService.sendAlarm1("007",errorMsg);
		}

        logger.info("export defect data successfull ......");
    }

    public void subMainProc2 () throws Exception {

        /**
         * get all work order by custom id
         */
        List<Ret_wo> woList = findAllWorkerOrder();

        String[] opeIds = { IQC_OPE_ID, DM_HXQC_OPE_ID};
        
        long time = beginTimestamp.getTime();
        DateTime beginDt = new DateTime(time);
        DateTime indexDt = beginDt.plusHours(-2);
        indexTimestamp = new Timestamp(indexDt.getMillis());
        
//        List<His_ret_prd_info> hisRetPrdInfoList = hisRetPrdInfoDao.findLogoffRecordsByOpe(woList, opeIds,
//                TimeUtil.getDoubleTimeByTimestamp(beginTimestamp), TimeUtil.getDoubleTimeByTimestamp(endTimestamp),indexTimestamp);
        
        List<His_ret_prd_info> hisRetPrdInfoList = hisRetPrdInfoDao.findLogoffRecordsByOpe(woList, opeIds,
                beginTimestamp, endTimestamp);

        logger.info("find {} records in HIS_RET_PRD_INFO", hisRetPrdInfoList.size());

        if (hisRetPrdInfoList.size() == 0) {
            return;
        }

        Map<String, List<His_ret_prd_info>> sheetHisMap = new HashMap<String, List<His_ret_prd_info>>();
        Set<String> sheetIdSet = new HashSet<String>();

        for (His_ret_prd_info hisRetPrdInfo : hisRetPrdInfoList) {
            String prdSeqId = hisRetPrdInfo.getPrd_seq_id();

            // distinct sheet
            sheetIdSet.add(prdSeqId);

            // group sheet history
            List<His_ret_prd_info> sheetHisList = null;
            if (sheetHisMap.containsKey(prdSeqId)) {
                sheetHisList = sheetHisMap.get(prdSeqId);
                sheetHisList.add(hisRetPrdInfo);
            } else {
                sheetHisList = new ArrayList<His_ret_prd_info>();
                sheetHisList.add(hisRetPrdInfo);
            }

            sheetHisMap.put(prdSeqId, sheetHisList);

        }
        /**
         * get SPC data recorders of cus_id:007 . query table SPC_RET_MFG_DATA,
         */

        // List<Ret_prd_jge> retPrdJgeList =
        // retPrdJgeDao.getDefectRecorders(beginTimestamp, endTimestamp,
        // ComDef.CUS_ID);
        List<Ret_prd_jge> retPrdJgeList = retPrdJgeDao.getDefectCordersBySheet(sheetIdSet);
        logger.info("find {} records in RET_PRD_JGE ", retPrdJgeList.size());

        /**
         * group judge info by sheet
         */
        Map<String, List<Ret_prd_jge>> sheetJudgeMap = new HashMap<String, List<Ret_prd_jge>>();
        for (Ret_prd_jge retPrdJge : retPrdJgeList) {
            String prdSeqId = retPrdJge.getPrd_seq_id_fk();
            List<Ret_prd_jge> sheetJudgeList = null;
            if (sheetJudgeMap.containsKey(prdSeqId)) {
                sheetJudgeList = sheetJudgeMap.get(prdSeqId);
                sheetJudgeList.add(retPrdJge);
            } else {
                sheetJudgeList = new ArrayList<Ret_prd_jge>();
                sheetJudgeList.add(retPrdJge);
            }
            sheetJudgeMap.put(prdSeqId, sheetJudgeList);
        }

        /**
         * get all pel_lvl from bis_ope
         */
        List<Bis_ope> opeInfos = bisOpeDao.getAllOpeInfos();
        Map<OpeKey, Integer> opeSeqMap = new HashMap<OpeKey, Integer>();
        for (Bis_ope bisOpe : opeInfos) {
            opeSeqMap.put(new OpeKey(bisOpe.getOpe_id(), bisOpe.getOpe_ver()), Integer.valueOf(bisOpe.getPep_lvl()));
        }

        setGlobalOpePelLvl(opeSeqMap);

        /**
         * get all sheets by cus_id query table RET_PRD_INFO by custom_id & time
         * period select * from ret_prd_info where wo_id_fk in ( select wo_id
         * from ret_wo where cus_id = '007')
         */

        List<Ret_prd_info> retPrdInfoList = retPrdInfoDao.getSheetList(sheetIdSet);
        for (Ret_prd_info retPrdInfo : retPrdInfoList) {
        	if (StringUtils.isBlank(retPrdInfo.getGroup_id())) {
				continue;
			}
            String prdSeqId = retPrdInfo.getPrd_seq_id();

            List<CsotDefectDataCsvEntity> defectDataEntityList = new ArrayList<CsotDefectDataCsvEntity>();

            defectDataEntityList = calculateDefectProc(sheetJudgeMap.get(prdSeqId), sheetHisMap.get(prdSeqId),
                    retPrdInfo, opeSeqMap);

            if (defectDataEntityList == null) {
                continue;
            }

            // build CSV file by spcDataEntityList
            String currentTime = TimeUtil.getRvTime();

            String fileName = getFtpConfigure().getLocalDefectGzPath() + "/DEFECT_" + retPrdInfo.getPrd_seq_id().split("_")[0] + "_"
                    + currentTime + ".csv";
            // compress file to *.gz
            String[] headers = { "BLOCK_ID", "FACTORY_ID", "PANEL_ID", "PRODUCT_ID", "OWNER_CODE", "OPERATOR_ID",
                    "TIME", "IQC_DEFECT_CODE", "MAIN_DEFECT_CODE", "SUB_DEFECT_CODE1", "SUB_DEFECT_CODE2" };
//            String[] headers = { "BLOCK_ID", "FACTORY_ID", "PANEL_ID", "PRODUCT_ID", "OWNER_CODE", "OPERATOR_ID",
//                "TIME", "IQC_DEFECT_CODE", "MAIN_DEFECT_CODE", "SUB_DEFECT_CODE1", "SUB_DEFECT_CODE2","PROCESS_ID" };

            List<String[]> bodyList = new ArrayList<String[]>();
            for (CsotDefectDataCsvEntity defectEntity : defectDataEntityList) {
                String[] body = new String[] { defectEntity.getBLOCK_ID(), defectEntity.getFACTORY_ID(),
                        convertPanelStyle(defectEntity.getPANEL_ID()), defectEntity.getPRODUCT_ID(),
                        defectEntity.getOWNER_CODE(), defectEntity.getOPERATOR_ID(), defectEntity.getTIME(),
                        defectEntity.getIQC_DEFECT_CODE(), defectEntity.getMAIN_DEFECT_CODE(),
                        defectEntity.getSUB_DEFECT_CODE1(), defectEntity.getSUB_DEFECT_CODE2() };
//                defectEntity.getSUB_DEFECT_CODE1(), defectEntity.getSUB_DEFECT_CODE2(),defectEntity.getPROCESS_ID() };
                logger.info(defectEntity.toString());
                bodyList.add(body);

            }
            try {

                logger.info("building csv File process [" + fileName + "]");
                CsvFileWriterUtil.writeCVS("SLIM_DEFECT_DATA_BEGIN", headers, bodyList, "SLIM_DEFECT_DATA_END",
                        fileName);

                logger.info("compress csv file process ....");
                GzCompressUtil.compress(new File(fileName));
                String gzFileName = fileName + ".gz";
                File gzFile = new File(gzFileName);

                // send to FTP Service
                ftpService.connect();
                ftpService.uploadFile(gzFile, getFtpConfigure().getFtpDefectExportPath());
                ftpService.disconnectFtp();
                logger.info("=============================================================================");

            } catch (Exception e) {
                logger.error(e.toString());
                throw e;
            }
        }

    }

    private void setGlobalOpePelLvl(Map<OpeKey, Integer> opeSeqMap) {
        global_IqcPelLvl = opeSeqMap.get(new OpeKey(IQC_OPE_ID, COMMON_OPE_VER));
        global_jbQaPelLvl = opeSeqMap.get(new OpeKey(JB_QA_OPE_ID, COMMON_OPE_VER));
        global_dmQaPelLvl = opeSeqMap.get(new OpeKey(DM_QA_OPE_ID, COMMON_OPE_VER));
    }

    private List<CsotDefectDataCsvEntity> calculateDefectProc(List<Ret_prd_jge> sheetRetPrdJgeList,
            List<His_ret_prd_info> sheetHislist, Ret_prd_info retPrdInfo, Map<OpeKey, Integer> opePepLvlMap) {
        List<CsotDefectDataCsvEntity> entityList = new ArrayList<CsotDefectDataCsvEntity>();
        String prdSeqId = retPrdInfo.getPrd_seq_id();

        // // TODO:测试代码，测试没有判定defect的玻璃
        // if (sheetRetPrdJgeList == null) {
        // return null;
        // }
        // get sheet's max pel_lvl from the list filtered by prd_seq_id
        // above
        int maxPepLvl = getMaxPelLvl(sheetHislist, opePepLvlMap);
        logger.info("sheet {} 's has {} history ,max pep_lvl is {} ", prdSeqId, sheetHislist.size(), maxPepLvl);

        /**
         * judge current QA stage JB-01, JB-10,DM-05
         */
        int currentQAStage = getCurrentQAStage(maxPepLvl);
        logger.info("sheet {}  stage : {} ", prdSeqId, currentQAStage);

        int xCnt = retPrdInfo.getX_axis_cnt();
        int yCnt = retPrdInfo.getY_axis_cnt();
        for (int i = 1; i <= yCnt; i++) {
            for (int j = 1; j <=xCnt ; j++) {
                String posId = i + "*" + j;
                CsotDefectDataCsvEntity entity = new CsotDefectDataCsvEntity();
                entity.setBLOCK_ID(prdSeqId.split("_")[0]);
                entity.setFACTORY_ID("WA");
                entity.setPANEL_ID(posId);
                entity.setPRODUCT_ID(retPrdInfo.getMdl_id_fk());
                entity.setOWNER_CODE(retPrdInfo.getGroup_id());
                entity.setTIME(getLastLogofTime(sheetHislist).substring(0, 19).replace("-", "/"));
                
                if (currentQAStage == STAGE_IQC) {
                  entity.setPROCESS_ID("JB-01");
                } else if (currentQAStage == STAGE_JB_QA) {
                  entity.setPROCESS_ID("DM-07");
                } else {
                  entity.setPROCESS_ID("DM-07");
                }
                
                if (sheetRetPrdJgeList == null) {
                    // logger.warn("sheet {} , pos {}  has not judge yet",
                    // prdSeqId, posId);
                    entityList.add(entity);
                    continue;
                    // // TODO:测试时打开，屏蔽没有判定defect的玻璃
                    // return null;
                }

                List<Ret_prd_jge> sheetPosJudgeList = new ArrayList<Ret_prd_jge>();
                // group judge info by sheet's position
                for (Ret_prd_jge retPrdJge : sheetRetPrdJgeList) {
                    if (posId.equals(retPrdJge.getDef_code1_lc())) {
                        sheetPosJudgeList.add(retPrdJge);
                    }
                }

                // // TODO:测试时打开，屏蔽没有判定defect的位置
                // if (sheetPosJudgeList.isEmpty()) {
                // continue;
                // }

                logger.info("sheet {} , pos {}  has {} judge recorders", prdSeqId, posId, sheetPosJudgeList.size());

                for (Ret_prd_jge retPrdJge : sheetPosJudgeList) {
                    logger.info("{} judge info : ope_id {} ,pep_Lvl {} , rsn_cate {} ,def_code_cnt {}", prdSeqId,
                            retPrdJge.getOpe_id_fk(), opePepLvlMap.get(new OpeKey(retPrdJge.getOpe_id_fk(), "00000")),
                            retPrdJge.getRsn_cate(), retPrdJge.getDef_code1_cnt());
                }

                if (currentQAStage == STAGE_IQC) {
                    /**
                     * only get JB-01 defect
                     */

                    logger.info("{} IQC stage ...", prdSeqId);
                    
                    // group judge info by sheet's position and ope_id
                    List<Ret_prd_jge> sheetPosOpeJudgeList = new ArrayList<Ret_prd_jge>();
                    for (Ret_prd_jge retPrdJge : sheetPosJudgeList) {
                        if (retPrdJge.getOpe_id_fk().equals(IQC_OPE_ID)
                                && retPrdJge.getOpe_ver_fk().equals(COMMON_OPE_VER)) {
                            sheetPosOpeJudgeList.add(retPrdJge);
                        }
                    }

                    if (sheetPosOpeJudgeList.isEmpty()) {
                        entityList.add(entity);
                        continue;
                    }

                    // sum judge_cnt
                    int sum = 0;
                    for (Ret_prd_jge retPrdJge : sheetPosOpeJudgeList) {
                        sum = sum + retPrdJge.getDef_code1_cnt();
                    }

                    logger.info("{} , pos {} defect cnt summary result is {} ", prdSeqId, posId, sum);
                    if (sum == 0) {
                        entityList.add(entity);
                        continue;
                    } else if (sum == 1) {
                        // get newest defect info
                        Ret_prd_jge newestRetPrdJge = null;
                        for(Ret_prd_jge retPrdJge : sheetPosOpeJudgeList){
                        	if(retPrdJge.getDef_code1_cnt() > 0){
                        		newestRetPrdJge = retPrdJge;
                        	}
                        }
                        for (Ret_prd_jge retPrdJge : sheetPosOpeJudgeList) {
                            if (retPrdJge.getDef_code1_cnt() > 0 &&  retPrdJge.getJudge_timestamp().after(newestRetPrdJge.getJudge_timestamp())) {
                                newestRetPrdJge = retPrdJge;
                            }
                        }
                        if ("M".equals(newestRetPrdJge.getRsn_cate())) {
                            entity.setIQC_DEFECT_CODE(newestRetPrdJge.getDef_code1());
                        } else if ("P".equals(newestRetPrdJge.getRsn_cate())) {
                            entity.setMAIN_DEFECT_CODE(newestRetPrdJge.getDef_code1());
                        }

                        entity.setOPERATOR_ID(newestRetPrdJge.getJudge_usr());
                        entity.setTIME(newestRetPrdJge.getJudge_timestamp().toString().substring(0, 19)
                                .replace("-", "/"));
                        entityList.add(entity);

                    } else {
                        // ERROR
                        entityList.add(entity);
                        continue;
                    }

                } else if (currentQAStage == STAGE_JB_QA) {
                    /*
                     * complex logic: 1.summary
                     */
                    logger.info("{} JB-QA stage ...", prdSeqId);
                    entity.setPROCESS_ID("DM-07");
                    // sum judge_cnt
                    int sum = 0;
                    for (Ret_prd_jge retPrdJge : sheetPosJudgeList) {
                        sum = sum + retPrdJge.getDef_code1_cnt();
                    }

                    logger.info("{} , pos {} defect cnt summary result is {} ", prdSeqId, posId, sum);
                    if (sum == 0) {
                        entityList.add(entity);
                        continue;
                    } else if (sum == 1) {
                        // get newest defect info
                       
                        
                        Ret_prd_jge newestRetPrdJge = null;
                        for(Ret_prd_jge retPrdJge : sheetPosJudgeList){
                        	if(retPrdJge.getDef_code1_cnt() > 0){
                        		newestRetPrdJge = retPrdJge;
                        	}
                        }
                        for (Ret_prd_jge retPrdJge : sheetPosJudgeList) {
                            if (retPrdJge.getDef_code1_cnt() > 0  && retPrdJge.getJudge_timestamp().after(newestRetPrdJge.getJudge_timestamp())) {
                                newestRetPrdJge = retPrdJge;
                            }
                        }
                        entity.setMAIN_DEFECT_CODE(newestRetPrdJge.getDef_code1());

                        entity.setOPERATOR_ID(newestRetPrdJge.getJudge_usr());
                        entity.setTIME(newestRetPrdJge.getJudge_timestamp().toString().substring(0, 19)
                                .replace("-", "/"));
                        entityList.add(entity);
                    } else {
                        // ERROR
                        entityList.add(entity);
                        continue;
                    }

                } else {// STAGE_DM_QA
                    /**
                     * only get DM-05
                     */
                    logger.info("{} DM-QA stage ...", prdSeqId);
                    entity.setPROCESS_ID("DM-07");
                    if (sheetPosJudgeList.isEmpty()) {
                        entityList.add(entity);
                        continue;
                    }

                    // sum judge_cnt
                    int sum = 0;
                    for (Ret_prd_jge retPrdJge : sheetPosJudgeList) {
                        sum = sum + retPrdJge.getDef_code1_cnt();
                    }

                    logger.info("{} , pos {} defect cnt summary result is {} ", prdSeqId, posId, sum);
                    if (sum == 0) {
                        entityList.add(entity);
                        continue;
                    } else if (sum == 1) {
                        // get newest defect info
                    	 Ret_prd_jge newestRetPrdJge = null;
                         for(Ret_prd_jge retPrdJge : sheetPosJudgeList){
                         	if(retPrdJge.getDef_code1_cnt() > 0){
                         		newestRetPrdJge = retPrdJge;
                         	}
                         }
                        for (Ret_prd_jge retPrdJge : sheetPosJudgeList) {
                            if (retPrdJge.getDef_code1_cnt() > 0 && retPrdJge.getJudge_timestamp().after(newestRetPrdJge.getJudge_timestamp())) {
                                newestRetPrdJge = retPrdJge;
                            }
                        }
                        entity.setMAIN_DEFECT_CODE(newestRetPrdJge.getDef_code1());

                        entity.setOPERATOR_ID(newestRetPrdJge.getJudge_usr());
                        entity.setTIME(newestRetPrdJge.getJudge_timestamp().toString().substring(0, 19)
                                .replace("-", "/"));
                        entityList.add(entity);
                    } else {
                        // ERROR
                        entityList.add(entity);
                        continue;
                    }
                }

            }
        }

        return entityList;
    }

    private int getMaxPelLvl(List<His_ret_prd_info> sheetHislist, Map<OpeKey, Integer> opePepLvlMap) {
        int max = 0;
        for (His_ret_prd_info hisRetPrdInfo : sheetHislist) {
            String opeId = hisRetPrdInfo.getCr_ope_id_fk();
            String opeVer = hisRetPrdInfo.getCr_ope_ver_fk();
            OpeKey opeKey = new OpeKey(opeId, opeVer);

            Integer pepLvl = opePepLvlMap.get(opeKey);
            if (pepLvl > max) {
                max = pepLvl;
            }
        }
        return max;
    }

    private int getCurrentQAStage(int maxPelLvl) {
        if (maxPelLvl >= global_IqcPelLvl && maxPelLvl < global_jbQaPelLvl) {
            return STAGE_IQC;
        } else if (maxPelLvl >= global_jbQaPelLvl && maxPelLvl < global_dmQaPelLvl) {
            return STAGE_JB_QA;
        }
        return STAGE_DM_QA;
    }

    /**
     * 
     */
    private void getTimePeriod() {
        DateTime dt = new DateTime();

        DateTime endDt = dt.plusMinutes(endTimeMak);
        endTimestamp = new Timestamp(endDt.getMillis());

        DateTime beginDt = endDt.plusHours(-1);
        beginTimestamp = new Timestamp(beginDt.getMillis());
        
        //strEndTime = getTimeFromDateTime(endDt);
        
        beginTimestamp.setNanos(0);
        endTimestamp.setNanos(0);

        logger.info("begin time:" + beginTimestamp);
        logger.info("end time :" + endTimestamp);
    }
    
    private String getTimeFromDateTime(DateTime dt) {
      return comInt2String(dt.getYear(), 4) + comInt2String(dt.getMonthOfYear(), 2)
               + comInt2String(dt.getDayOfMonth(), 2) + comInt2String(dt.getHourOfDay(), 2)
               + comInt2String(dt.getMinuteOfHour(), 2) + comInt2String(dt.getSecondOfMinute(),2);
    }
    
    public String comInt2String(int value, int length) {
      String s = String.valueOf(value);
      if (s.length() > length) {
          throw new RuntimeException("length is too short.");
      } else if (s.length() == length) {
          return s;
      } else {
          char[] cc = new char[length];
          int i = 0;
          for (; i < length - s.length(); i++) {
              cc[i] = '0';
          }
          for (int j = 0; j < s.length(); i++, j++) {
              // System.out.println(i);
              cc[i] = s.charAt(j);
          }
          return new String(cc);
      }
  }

    private String convertPanelStyle(String posId) {
        int index = posId.indexOf("*");

        String strX = posId.substring(0, index);
        String strY = posId.substring(index+1);
        
        int x = Integer.valueOf(strX);
        int y = Integer.valueOf(strY);
        String panelId = formatNumber(x) + "" + formatNumber(y);
        logger.info(strX + " , " + strY + "==>" + panelId);
        return panelId;
    }

    private String formatNumber(int num) {
        String str = null;
        if (num <= 9) {
            str = String.valueOf(num);
        } else if(num <= 33) {
            switch (num) {
            case 10:
                str = "A";
                break;
            case 11:
                str = "B";
                break;
            case 12:
                str = "C";
                break;
            case 13:
                str = "D";
                break;
            case 14:
                str = "E";
                break;
            case 15:
                str = "F";
                break;
            case 16:
                str = "G";
                break;
            case 17:
                str = "H";
                break;
            case 18:
                str = "J";
                break;
            case 19:
                str = "K";
                break;
            case 20:
                str = "L";
                break;
            case 21:
                str = "M";
                break;
            case 22:
                str = "N";
                break;
            case 23:
                str = "P";
                break;
            case 24:
                str = "Q";
                break;
            case 25:
                str = "R";
                break;
            case 26:
                str = "S";
                break;
            case 27:
                str = "T";
                break;
            case 28:
                str = "U";
                break;
            case 29:
                str = "V";
                break;
            case 30:
                str = "W";
                break;
            case 31:
                str = "X";
                break;
            case 32:
                str = "Y";
                break;
            case 33:
                str = "Z";
                break;
            }
        }else{
            str = "Z";
        }
        return str;
    }
    private String getLastLogofTime(List<His_ret_prd_info> sheetHislist){
    	Double temp=0d;
    	for (His_ret_prd_info his_ret_prd_info : sheetHislist) {
			if(his_ret_prd_info.getEvt_cate().equals("LGOF")){
				if(temp<his_ret_prd_info.getSta_time_d()){
					temp=his_ret_prd_info.getSta_time_d();
				}
			}
		}
    	System.out.println(TimeUtil.getTimestampByDblTime(temp));
    	return TimeUtil.getTimestampByDblTime(temp);
    }
    public static void main(String[] args) {
        new CsotExportDefectInfoJob().getTimePeriod();
    }

    public Timestamp getBeginTimestamp() {
        return beginTimestamp;
    }

    public void setBeginTimestamp(Timestamp beginTimestamp) {
        this.beginTimestamp = beginTimestamp;
    }

    public Timestamp getEndTimestamp() {
        return endTimestamp;
    }

    public void setEndTimestamp(Timestamp endTimestamp) {
        this.endTimestamp = endTimestamp;
    }

    public FtpConfigure getFtpConfigure() {
        return ftpConfigure;
    }

    public void setFtpConfigure(FtpConfigure ftpConfigure) {
        this.ftpConfigure = ftpConfigure;
    }

    private List<Ret_wo> findAllWorkerOrder() {
        return retWoDao.findWoListByCusId(ComDef.CUS_ID);
    }

    public IFtpService getFtpService() {
        return ftpService;
    }

    public void setFtpService(IFtpService ftpService) {
        this.ftpService = ftpService;
    }

	public int getEndTimeMak() {
		return endTimeMak;
	}

	public void setEndTimeMak(int endTimeMak) {
		this.endTimeMak = endTimeMak;
	}

    public String getStrEndTime() {
      return strEndTime;
    }
  
    public void setStrEndTime(String strEndTime) {
      this.strEndTime = strEndTime;
    }
   
}
